package com.cbj.netty.rpc;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Godc
 * @description 单例的注册中心，简易版本，就是服务端启动时将所有的实现类加入到map中
 */
public class Dispatcher {
    private static final Dispatcher DISPATCHER;
    private Dispatcher(){
    }
    public static Dispatcher getDispatcher(){
        return DISPATCHER;
    }
    static {
        DISPATCHER = new Dispatcher();
    }
    public static ConcurrentHashMap<String,Object> invokeMap = new ConcurrentHashMap<>();
    public void register(String k,Object obj){
        invokeMap.putIfAbsent(k,obj);
    }
    public Object get(String k){
        if(k.equals("")||k==null){
            return null;
        }
        return invokeMap.get(k);
    }
}
